<?php

declare(strict_types=1);

namespace app\model\system;

use owns\interface\OwnsModelInteface;

class UserModel extends OwnsModelInteface
{
    protected $name = 'system_user';

    protected $field = [];

    /*
    * 限制超管账号
    */
    public function scopeUser($query)
    {
        $query->where('id', '>', 1);
    }
    /**
     * 管理员显示字段
     */
    public static function showField(): array
    {
        return [
            'id','username','nickname','phone','email','avatar','signed','dashboard',
            'sex','role_id','group_id','remark','created_at'
        ];
    }
    /**
     * 角色
     */
    public function role()
    {
        return $this->hasOne(RoleModel::class, 'id', 'role_id')->field('id,name,alias');
    }
    /**
     * 分组
     */
    public function group()
    {
        return $this->hasOne(UserGroupModel::class, 'id', 'group_id')->field('id,name,leader,phone');
    }

}
